<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="friendship" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{friendshipHome.managed ? 'Edit' : 'Add'} Friendship</f:facet>


            <s:decorate id="user1Field" template="layout/edit.xhtml">
                <ui:define name="label">User1</ui:define>
                <h:inputText id="user1"
                       required="true"
                       disabled="#{friendshipHome.managed}"
                          value="#{friendshipHome.instance.id.user1}">
                    <a:support event="onblur" reRender="user1Field" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>

            <s:decorate id="user2Field" template="layout/edit.xhtml">
                <ui:define name="label">User2</ui:define>
                <h:inputText id="user2"
                       required="true"
                       disabled="#{friendshipHome.managed}"
                          value="#{friendshipHome.instance.id.user2}">
                    <a:support event="onblur" reRender="user2Field" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="confirmedField" template="layout/edit.xhtml">
                <ui:define name="label">Confirmed</ui:define>
                <h:selectBooleanCheckbox id="confirmed"
                                      value="#{friendshipHome.instance.confirmed}"/>
            </s:decorate>



            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{friendshipHome.persist}"
                       disabled="#{!friendshipHome.wired}"
                       rendered="#{!friendshipHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{friendshipHome.update}"
                       rendered="#{friendshipHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{friendshipHome.remove}"
                      immediate="true"
                       rendered="#{friendshipHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Friendship.xhtml"
                rendered="#{friendshipHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty friendshipFrom ? 'FriendshipList' : friendshipFrom}.xhtml"
                rendered="#{!friendshipHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="User1">
    <div class="association" id="user1Parent">

        <h:outputText value="There is no user1 associated with this friendship."
                   rendered="#{friendshipHome.instance.user1 == null}"/>

        <rich:dataTable var="_user"
                   value="#{friendshipHome.instance.user1}"
                rendered="#{friendshipHome.instance.user1 != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="user1Table">
            <h:column>
                <f:facet name="header">Id</f:facet>
                <h:outputText value="#{_user.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Dsc</f:facet>
                <h:outputText value="#{_user.dsc}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Email</f:facet>
                <h:outputText value="#{_user.email}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Firstname</f:facet>
                <h:outputText value="#{_user.firstname}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Lastloggedin</f:facet>
                <h:outputText value="#{_user.lastloggedin}">
                    <s:convertDateTime type="both" dateStyle="short"/>
                </h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Lastname</f:facet>
                <h:outputText value="#{_user.lastname}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Password</f:facet>
                <h:outputText value="#{_user.password}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Registered</f:facet>
                <h:outputText value="#{_user.registered}">
                    <s:convertDateTime type="both" dateStyle="short"/>
                </h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Role id</f:facet>
                <h:outputText value="#{_user.role.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Status id</f:facet>
                <h:outputText value="#{_user.status.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Username</f:facet>
                <h:outputText value="#{_user.username}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{friendshipHome.instance.user1 != null ? 'changeParent' : 'selectParent'}" value="#{friendshipHome.instance.user1 != null ? 'Change' : 'Select'} user1"
                       view="/UserList.xhtml">
                <f:param name="from" value="FriendshipEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="User2">
    <div class="association" id="user2Parent">

        <h:outputText value="There is no user2 associated with this friendship."
                   rendered="#{friendshipHome.instance.user2 == null}"/>

        <rich:dataTable var="_user"
                   value="#{friendshipHome.instance.user2}"
                rendered="#{friendshipHome.instance.user2 != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="user2Table">
            <h:column>
                <f:facet name="header">Id</f:facet>
                <h:outputText value="#{_user.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Dsc</f:facet>
                <h:outputText value="#{_user.dsc}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Email</f:facet>
                <h:outputText value="#{_user.email}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Firstname</f:facet>
                <h:outputText value="#{_user.firstname}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Lastloggedin</f:facet>
                <h:outputText value="#{_user.lastloggedin}">
                    <s:convertDateTime type="both" dateStyle="short"/>
                </h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Lastname</f:facet>
                <h:outputText value="#{_user.lastname}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Password</f:facet>
                <h:outputText value="#{_user.password}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Registered</f:facet>
                <h:outputText value="#{_user.registered}">
                    <s:convertDateTime type="both" dateStyle="short"/>
                </h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Role id</f:facet>
                <h:outputText value="#{_user.role.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Status id</f:facet>
                <h:outputText value="#{_user.status.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Username</f:facet>
                <h:outputText value="#{_user.username}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{friendshipHome.instance.user2 != null ? 'changeParent' : 'selectParent'}" value="#{friendshipHome.instance.user2 != null ? 'Change' : 'Select'} user2"
                       view="/UserList.xhtml">
                <f:param name="from" value="FriendshipEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
